
/*
 * @author Javier A. Ramírez M.
 * jaramirez85@yahoo.es
 */

package com.jav.per;

import com.jav.inter.Constantes;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;


public class PersisSetup implements Constantes{

    
    private String user;
    private String pass;
    private String url_server;
    private boolean envio;  //1 envia 0 no envia

    public boolean isEnvio() {
        return envio;
    }

    public void setEnvio(boolean envio) {
        this.envio = envio;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    public String getUrl_server() {
        return url_server;
    }

    public void setUrl_server(String url_server) {
        this.url_server = url_server;
    }



    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }




    public byte[] persist() throws IOException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        DataOutputStream dout = new DataOutputStream(bout);
        try{
            dout.writeUTF(getUser());
            dout.writeUTF(getPass());
            dout.writeUTF(getUrl_server());
            dout.writeBoolean(isEnvio());
            dout.flush();
        }
        finally{
            if(dout!= null){
                 dout.close();
            }
            if(bout!= null){
                 bout.close();
            }
        }
        return bout.toByteArray();

    }

    public void resurrect(byte[] by) throws IOException {
        ByteArrayInputStream bin = new ByteArrayInputStream(by);
        DataInputStream din = new DataInputStream(bin);
        setUser(din.readUTF());
        setPass(din.readUTF());
        setUrl_server(din.readUTF());
        setEnvio(din.readBoolean());
        bin.close();
        din.close();
    }


}
